#include <stdio.h>
int main()
{
    int n,l[10000];
    while (scanf("%d",&n)!=EOF)
    {
        if (n==0)break;
        int i,maxSum=-10000000,thisSum=0,a=0,b,a1,t=0;
        for (i=0;i<n;i++)
        {
            scanf("%d",&l[i]);
            thisSum+=l[i];
            if (thisSum>maxSum)
            {
                maxSum=thisSum;
                a1=a;
                b=i;
            }
            if (thisSum<0){thisSum=0;a=i+1;}
        }
        if (maxSum<0){a=0;b=n-1;maxSum=0;}
        printf("%d %d %d\n",maxSum,l[a1],l[b]);
    }
    return 0;
}

